package com.example.zhinongbao.presenter;

import com.example.zhinongbao.Model.IUpdatePassword;
import com.example.zhinongbao.contract.UpdatePasswordContact;
import com.example.zhinongbao.entity.UserInfo;

public class UpdatePasswordPresenter {
    private UpdatePasswordContact updatePasswordContact ;
    private IUpdatePassword iUpdatePassword ;
    public UpdatePasswordPresenter(UpdatePasswordContact contact , IUpdatePassword updatePassword){
        this.updatePasswordContact = contact ;
        this.iUpdatePassword = updatePassword ;}
    public void updatePassword(String username , String oldPassword , String password){
        UserInfo user = iUpdatePassword.getUserByName(username);
        if (!password.equals(user.getPassword()) && oldPassword.equals(user.getPassword())){
           iUpdatePassword.updateLoginPassword(username,password);
        }
    }
    public boolean updateLoginSuccessful(String username , String password){
        UserInfo user = iUpdatePassword.getUserByName(username);
        if (password.equals(user.getPassword())){
            return  true;
        }else {
            return false ;
        }
    }

    public void updatePayPassword(String username , String password){
        UserInfo user = iUpdatePassword.getUserByName(username);
            if (!password.equals(user.getPaypassword())){
                iUpdatePassword.updatePayPassword(username, password);
        }

    }
    public boolean oldPawIsTure(String username , String password){
        UserInfo user = iUpdatePassword.getUserByName(username);
        if (password.equals(user.getPaypassword())){
            return true ;
        }else {
            return false ;
        }
    }
    public boolean updatePaySuccessful(String username , String password){
        UserInfo user = iUpdatePassword.getUserByName(username);
        if (password.equals(user.getPaypassword())){
            return  true;
        }else {
            return false ;
        }
    }

}
